<?
	if(isset($_GET['u_id'])){
		$u_id = intval($_GET['u_id']);
	}else{
		if(isset($_SESSION['uid'])){
			$u_id = $_SESSION['uid'];
		}else{
			header("Location: ".$root."/trang-chu/");
		}
	}
		

	///////////////////
	$sql = "SELECT A.*, B.* FROM ".$prefix."nguoidung AS A, ".$prefix."ketban as B WHERE A.u_id = B.kb_friend_id AND B.kb_uid = '".$u_id."' AND B.kb_trangthai = 1";
	
	if(isset($_POST['submit'])){
		$txtKeyword = addslashes($_POST['txtKeyword']);
		$sql .= " AND A.u_name like '%".$txtKeyword."%'";
	}
	
	if(isset($_GET['sid'])){
		$sid = intval($_GET['sid']);
		if($sid == 1){
			$sql .= " ORDER BY B.kb_friend_id DESC";
		}else if($sid == 2){
			$sql .= " ORDER BY B.kb_id DESC";
		}else if($sid == 3){
			$sql .= " ORDER BY A.u_name ASC";
		}else if($sid == 4){
			$sql .= " ORDER BY A.u_name DESC";
		}else{
			$sql = $sql;
		}
	}
	$pp=10; 
	$parr=array();
	$parr=paging($sql,$pp);
	$page=$parr[0];
	$limitvalue=$parr[1];
	$numofpages=$parr[2];
	$sql.=" LIMIT $limitvalue, $pp";
	$rs = $db->query($sql);
	
	
	//////////////////////XOA BAN BE ////////////////
	
		if(isset($_GET['act']) && ($_GET['act'] == 'del_banbe') ){
			if(isset($_GET['kb_id'])){
				$kb_id = intval($_GET['kb_id']);
			}else{
				header("Location: ".$root."/?mod=banbe&sid=".$sid."&p=".$p."");
			}
			$db->query("DELETE FROM ".$prefix."ketban WHERE kb_id = '".$kb_id."'");
			header("Location: ".$root."/?mod=banbe&p=".$p."&sid=".$sid."");
		}
?>
<script language="javascript">
	function funSapXep(id,p){
		window.location='<?=$root?>/?mod=banbe&sid=' + id + '&p=' + p;
	}
</script>
<div id="linkPath">       
<div class="linkPath">
    <div class="corner-round-01-top-right">
        <div class="corner-round-01-top-left">
            <div class="corner-round-01-top-bg"></div>
        </div>

    </div>
    <div class="corner-round-01-body">    
        <?
			file_exist('includes/inc_thong_tin_rieng.php');
			include('includes/inc_thong_tin_rieng.php');	
		?>

        <div style="clear: both;"></div>
    </div>
    <div class="corner-round-01-bottom-right">
        <div class="corner-round-01-bottom-left">
            <div class="corner-round-01-bottom-bg"></div>
        </div>
    </div>   
</div>
        
    </div>
    <!-- Main Page-Content { -->
    <div id="page-content">                    
        
<div id="page-content-lpane">
    <div id="menuleft" class="menucategory">
        <div class="category-header-right menucategory">
            <div class="category-header-left">
                <div class="category-header-bg" style="text-align:left;padding-left:20px">
                    <p>Danh sách</p>

                </div>
            </div>
        </div> 
        <div class="corner-round-05-top-right">
            <div class="corner-round-05-top-left">
                <div class="corner-round-05-top-bg"></div>
            </div>
        </div>
        <div class="corner-round-05-body">        
            <div id="product-category">            
                <div style="padding-top:5px;"></div>

                    <div class="friend-groups">                        
                        <ul id="groups-list">                            
                            <!-- begin for -->
                            <li>   <span>Danh sách bạn bè</span></li>
                            <!-- end for -->
                        </ul>
                        <p class="groupForm">
                            <label>Tìm kiếm</label> 
							
						<form action="" name="frmSearch" id="frmSearch" method="post">
						
                            <input type="text" id="txtKeyword" maxlength="50" /> 
							<input type="hidden" name="submit" id="submit" value="1" />
                            <input type="image" src="<?=$root?>/themes/images/home/search.png" name="btnSearch" id="btnSearch"/>
						</form>
                            <span>Nhập tài khoản bạn bè</span>
                        </p>
                    </div>
                </div>
            <div style="height:10px"></div>
        </div>

        <div class="corner-round-05-bottom-right">
            <div class="corner-round-05-bottom-left">
                <div class="corner-round-05-bottom-bg"></div>
            </div>
        </div>
        <br style="font-size:0px;" />
    </div>
</div>
<div id="friend-content-mpane-all">
    <div id="filtersDescription">

        <div class="corner-round-04-top-right">
            <div class="corner-round-04-top-left">
                <div class="corner-round-04-top-bg"></div>
            </div>
        </div>    
        <div class="corner-round-04-body">         
            <ul style="margin: 0px;" id="descriptionBar">
				 <li style="margin: 0px; float: left; line-height: 20px;" id="showTotalRecords">Tổng số <b class="highline"><?=$db->num_rows($rs)?></b> bạn.</li>

                <li style="margin: 0px; float: right;">
                   
					
					<div style="margin-right:2px;">
                         Sắp xếp theo: 
						<select name="sapxep" id="sapxep" onchange="funSapXep(this.value,'<?=$p?>');">
							<option value="0" <? if($sid==0){?> selected="selected" <? }?>>--- Tất cả ---</option>
							<option value="1" <? if($sid==1){?> selected="selected" <? }?>>Mới cập nhật</option>
							<option value="2" <? if($sid==2){?> selected="selected" <? }?>>Mới thêm</option>
							<option value="3" <? if($sid==3){?> selected="selected" <? }?>>A-Z</option>
							<option value="4" <? if($sid==4){?> selected="selected" <? }?>>Z-A</option>
						</select>  
                    </div> 

                                    
                </li>  
                                           
            </ul>

            <p style="font-size: 0pt;" class="clearBoth"></p>
        </div>
        <div class="corner-round-04-bottom-right">
            <div class="corner-round-04-bottom-left">
                <div class="corner-round-04-bottom-bg"></div>
            </div>   
        </div>
    </div>    
    <div id="friendlists">
        <div id="friendlists-header">

            <label id="selectGroup">Dách sách bạn bè</label>
        </div>
        <div id="friendlist-body">
            <div class="corner-round-05-top-right">
                <div class="corner-round-05-top-left">
                    <div class="corner-round-05-top-bg"></div>

                </div>
            </div>
            <div class="corner-round-05-body2">
                
                    <div id="friend-list" class="friend-list">
                       
				
		<!-- LIST FRIEND -->		
			
			<?
					while($row = $db->fetch_array($rs)){
					$kb_id = $row[kb_id];
					$kb_friend_id = $row[kb_friend_id];
					$u_name = stripslashes($row[u_name]);
					$u_avatar = $PathThumbFile . $row[u_avatar];
					$u_tenshop = $myString->unQuote(stripslashes($row[u_tenshop]));
					$u_ngaysinh = format_date($row[u_ngaysinh]);
					$u_diachi = $myString->unQuote(stripslashes($row[u_diachi]));
			?>	
					   
					    <div class="friend-item">   
								<div cid="381688" class="panel-left popup-profile">       
								<a target="_blank" href="<?=$root?>/shop-<?=$kb_friend_id?>/<?=$u_name?>" title="<?=$u_name?>">
								<img src="<?=$u_avatar?>" alt="<?=$u_name?>" border="0" onerror="this.src='<?=$root?>/themes/images/noavatar.jpg';" width="60" height="60">
								</a> 
								
								<a target="_blank" title="<?=$u_name?>" href="<?=$root?>/shop-<?=$kb_friend_id?>/<?=$u_name?>"><?=banned($u_id,$myString->cutString2($u_name,6))?></a>   
								</div> 
								<style>
									.table3 td{
										padding:1px;
									}
								</style>  
								<div style="display: block;" class="panel-right-show-note"> 
									<span class="pointer"></span>  
									<table border="0" cellpadding="0" cellspacing="0" class="table3">
										<tr>
											<td align="right">Tên shop : </td>
											<td><b><?=$u_tenshop?></b></td>
										</tr>
										<tr>
											<td align="right">Ngày sinh : </td>
											<td><?=$u_ngaysinh?></td>
										</tr>
										<tr>
											<td align="right">Địa chỉ : </td>
											<td><?=$u_diachi?></td>
										</tr>
									</table>     
								</div>   
								<p style="clear: both; text-align: right;">
								<br style="line-height:5px;">
								<a href="<?=$root?>/shop-<?=$kb_friend_id?>/<?=$u_name?>">Xem</a> | <a href="<?=$root?>/?mod=banbe&act=del_banbe&kb_id=<?=$kb_id?>">Xóa</a>
								</p>
						</div>
			<? } 
				
			if($db->num_rows($rs) == 0){
			
			?>			
			<span>Chưa có bạn bè nào !</span>
			
			<? } ?>

                    </div>
          
            </div>
            <div class="corner-round-05-bottom-right">
                <div class="corner-round-05-bottom-left">
                    <div class="corner-round-05-bottom-bg"></div>
                </div>
            </div>
        </div>

        <div id="paging">
            <div class="corner-round-01-top-right">
                <div class="corner-round-01-top-left">
                    <div class="corner-round-01-top-bg"></div>
                </div>
            </div>

            <div style="text-align: right;" class="corner-round-01-body">            
                <div id="friend-paging">
				<p align="center" class="font">
				 <?php echo page_div( "".$root."/?mod=banbe&sid=".$sid."&p=%d_pg", "10", ceil ( $numofpages ), $page ); ?>
				 </p>
				</div>
            </div>
            <div class="corner-round-01-bottom-right">
                <div class="corner-round-01-bottom-left">
                    <div class="corner-round-01-bottom-bg"></div>
                </div>
            </div>   
        </div>
    </div>

</div>
    </div>
    <div style="clear:both;"></div>
    <!-- } Main Page-Content -->

            </div>
